import { Controller, Post, Body, Get, Query } from '@nestjs/common';
import { AiService } from './ai.service';

@Controller('system/ai')
export class AiController {
  constructor(private readonly aiService: AiService) {}

  /**
   * 通用的对话接口
   */
  @Post('chat')
  async chat(@Body() body: { messages: Array<{ role: 'system' | 'user' | 'assistant'; content: string }>; model?: string }) {
    return this.aiService.generateCompletion(body.messages, body.model);
  }

  /**
   * 简单的问答接口
   */
  @Get('ask')
  async ask(@Query('question') question: string, @Query('systemPrompt') systemPrompt?: string) {
    if (!question) {
      throw new Error('问题不能为空');
    }
    return this.aiService.askQuestion(question, systemPrompt);
  }

  /**
   * 生成AI报告
   */
  @Get('generateAIReport')
  async generateAIReport() {
    console.log('开始生成AI报告');
    return this.aiService.generateAIReport();
  }

  /**
   * 获取语音转文字token
   */
  @Get('getTSSToken')
  async getTSSToken() {
    return this.aiService.createToken();
  }

  /**
   * 发送消息
   */
  @Get('send')
  async send() {
    return this.aiService.sendChatMessage();
  }
}
